package com.typhoon.extend.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.typhoon.extend.dto.RoleDto;
import com.typhoon.extend.dto.request.QueryRoleReq;
import com.typhoon.extend.service.RoleService;
import com.typhoon.extend.util.CommonUtils;
import com.typhoon.extend.util.PageHolder;

@Controller
@RequestMapping("/role")
public class RoleController extends BaseController {

	private static final Logger LOGGER = LoggerFactory.getLogger(RoleController.class);
	
	@Resource
	RoleService roleService;
	
	 @RequestMapping(value = "/page.do")
	 public void queryUserByCondition(HttpServletRequest request, HttpServletResponse response) {
		 
		 int pageSize = CommonUtils.evalInt(request.getParameter("pageSize"),20);
		 int pageIndex = CommonUtils.evalInt(request.getParameter("pageIndex"),1);
		 
		 QueryRoleReq req = new QueryRoleReq();
		 String roleName = CommonUtils.evalString(request.getParameter("roleName"));
		 if(StringUtils.isNotBlank(roleName)) {
			 req.setRoleName(roleName);
		 }
		 try {
			 PageHolder<RoleDto> page = this.roleService.queryPageByCondition(req, pageSize, pageIndex);
			 this.putSuccessResult(response,page);
		} catch (Exception e) {
			LOGGER.error("查询角色信息异常",e);
			this.putFailtResult(response,"查询角色信息异常");
		}
		 
	 }
	
	
}
